#include "Tester.h"

#ifdef __MEMORYTESTER__ON

#include <cstdlib>

#include <Game.h>

#include <Support\Config.h>
#include <Support\Log.h>
// #include <Support\GAssert.h>
#include <Support\Storage.h>
#include "Spacewar.h"


std::ofstream	logBuffer;


bool initiator_storage(Game* game, const char* configurationFile)
{
	bool initStatus = true;

	return game->initialize(NULL, configurationFile);
}

bool terminator_storage(Game* game)
{
	return game->shutdown();
}

void logConfiguration_storage()
{
	static const char* ENGINE_NAME = "Poget";
	static const char* ENGINE_VERSION = "1.0";

	std::string options;
	gConfig.getConfigureOptions(options);

	std::string message;
	message = "Initialization Complete\n";
	message += ENGINE_NAME;
	message += " Version ";
	message += ENGINE_VERSION;
	message += "\nConfiguration Options\n";
	message += options;
	gLog(message.c_str());
}

bool starting_storage(Game* game, const char* configurationFile)
{
	bool result = initiator_storage(game, configurationFile);
	if (result)
		logConfiguration_storage();
	return result;
}

void ending_storage(Game* game)
{
	EXPECT_TRUE(terminator_storage(game));
}

TEST(StorageManager, MemoryTest)
{
	Spacewar game;
	bool result = false;
	const char* CONFIGURATION_FILE_1 = "C:\\Projects\\EngineV1.0\\Tester\\ManagementFiles\\physicalmemory.txt";
	result = starting_storage(&game, CONFIGURATION_FILE_1);
	
	int *testInt = (int*)gStorageManager.New(sizeof(int));
	int *testInt2 = (int*)gStorageManager.New(sizeof(int));
	//int *intArray = (int*) gStorageManager.NewArray(sizeof(int), 3);
	*testInt = 15;
	*testInt2 = 23;
	//intArray[0] = 4;
	//intArray[1] = intArray[0] + 5;

	//*testInt = 5;
	//intArray[2] = intArray[1] + 15;

	int x = *testInt + *testInt2;

	gStorageManager.Delete(testInt);
	gStorageManager.Delete(testInt2);


	EXPECT_TRUE(result);
	if (result)
	{
		ending_storage(&game);
	}

}

#endif

